﻿using System;

namespace Cpu6502.Opcodes
{
    class BIT_A : Opcode
    {
        public BIT_A()
        {
            this.CpuCycles = 4;
            this.AddressType = CPU.AddressType.Absolute;
        }
        public override void Execute()
        {
            Byte data =
                CPU.Memory
                [
                    MemoryHelper.GetAddress
                    ((Int16)base.Argument, CPU.AddressType.Absolute)
                ];

            // Set Flags
            CPU.Registers.P.N = (((data << 7) & 1) != 0);
            CPU.Registers.P.V = ((0x40 & data) == 1);            
            CPU.Registers.P.Z = ((data & CPU.Registers.A) == 0);            
        }
    }

    class BIT_ZP : Opcode
    {
        public BIT_ZP()
        {
            this.CpuCycles = 3;
            this.AddressType = CPU.AddressType.ZeroPage;
        }
        public override void Execute()
        {
            Byte data =
                CPU.Memory
                [
                    MemoryHelper.GetAddress
                    ((Int16)base.Argument, CPU.AddressType.ZeroPage)
                ];

            // Set Flags
            CPU.Registers.P.N = (((data << 7) & 1) != 0);
            CPU.Registers.P.V = ((0x40 & data) == 1);
            CPU.Registers.P.Z = ((data & CPU.Registers.A) == 0);
        }
    }
}
